package Scene6;
import Picture.GameImage;
import javax.swing.*;
import java.awt.image.BufferedImage;
public class Tree2 {
    BufferedImage img = GameImage.get("/Picture/images/树苗3.png");
    int x = 750;
    int y = 420;
    int state = 0;
    int experience = 0;
    int want = 0;//0为无需求;1为水;2为除草;3为肥料
    Fertilizer fertilizer;
    Shovel shovel;
    Bucket bucket;
    TreePanel panel;
    int flag1 = 0;
    int flag2 = 0;


    public Tree2(Fertilizer fertilizer, Shovel shovel, Bucket bucket, TreePanel panel){
        this.bucket = bucket;
        this.shovel = shovel;
        this.fertilizer = fertilizer;
        this.panel = panel;
    }
    public void reOpen(){
        experience = 0;
        want = 0;//0为无需求;1为水;2为除草;3为肥料
        flag1 = 0;
        flag2 = 0;
    }
    public void changeState(){
        if(experience==2&&flag1==0){
            flag1 = 1;
            img = GameImage.get("/Picture/images/中间过程2.png");
            y=y-img.getHeight()+120;

        }
        if(experience==5&&flag2==0){
            flag2 = 1;
            img = GameImage.get("/Picture/images/tree2.png");
            y = y-img.getHeight()+300;
            x-=160;
        }
    }

    public void changeWant(){
        if(panel.now<=58&&experience==0){
            want = 1;
        }
        if(panel.now<=41&&experience==1){
            want = 3;
        }
        if(panel.now<=39&&experience==2){
            want = 3;
        }
        if(panel.now<=29&&experience==3){
            want = 3;
        }
        if(panel.now<=8&&experience==4){
            want = 1;
        }
    }

    public void absorb(){
        if(want==3&&this.x-20<fertilizer.x&&fertilizer.x<(this.x+this.img.getWidth())+20&&
                this.y-20<fertilizer.y&&fertilizer.y<(this.y+this.img.getHeight())+20){
            experience++;
            fertilizer.x = 50;
            fertilizer.y = 580;
            want = 0;
            panel.Canusefertilizer= false;
        }
        if(want==2&&this.x-20<shovel.x&&shovel.x<(this.x+this.img.getWidth())+20&&
                this.y-20<shovel.y&&shovel.y<(this.y+this.img.getHeight())+20){
            experience++;
            shovel.x = 50;
            shovel.y = 300;
            want = 0;
            panel.Canuseshovel = false;
        }
        if(want==1&&this.x-20<bucket.x&&bucket.x<(this.x+this.img.getWidth())+20&&
                this.y-20<bucket.y&&bucket.y<(this.y+this.img.getHeight())+20){
            experience++;
            bucket.x = 50;
            bucket.y = 40;
            want = 0;
            panel.Canusebucket = false;
        }
    }
}
